import { EllipsisOutlined, PlusOutlined } from "@ant-design/icons";
import { ProTable, TableDropdown } from "@ant-design/pro-components";
import { Button, Dropdown, Menu, Space, Tag } from "antd";
import { useRef } from "react";
import {cakeGet} from '@/api/cake'
// import request from "umi-request";
const columns = [
  {
    dataIndex: "objectId",
    valueType: "indexBorder",
    width: 48,
  },
  {
    title: "商品名称",
    dataIndex: "name",
    copyable: true,
    ellipsis: true,
    filters: true,
    onFilter: true,
  },
  {
    disable: true,
    title: "简介",
    dataIndex: "chineseBrief",
    filters: false,  //是否作为查询条件
    search:false,
    // onFilter: true,
    ellipsis: true,
  },
  {
    disable: true,
    title: "价格",
    dataIndex: "price",
    sorter: true,
    filters: false,
    search:false
  },
  {
    title: "归属分类",
    key: "bcname",
    dataIndex: "bcname",
    filters: true,
    onFilter: true,
    // search:false //控制该字段是否为查询条件
  },
  {
    title: "操作",
    valueType: "option",
    key: "option",
    render: (text, record, _, action) => [
      <a
        key="editable"
        onClick={() => {
          var _a;
          (_a =
            action === null || action === void 0
              ? void 0
              : action.startEditable) === null || _a === void 0
            ? void 0
            : _a.call(action, record.id);
        }}
      >
        编辑
      </a>,
      <a href={record.url} target="_blank" rel="noopener noreferrer" key="view">
        查看
      </a>,
      <TableDropdown
        key="actionGroup"
        onSelect={() =>
          action === null || action === void 0 ? void 0 : action.reload()
        }
        menus={[
          { key: "copy", name: "复制" },
          { key: "delete", name: "删除" },
        ]}
      />,
    ],
  },
];
const menu = (
  <Menu>
    <Menu.Item key="1">1st item</Menu.Item>
    <Menu.Item key="2">2nd item</Menu.Item>
    <Menu.Item key="3">3rd item</Menu.Item>
  </Menu>
);
export default function CartList() {
  const actionRef = useRef();
  return (
    <ProTable
      columns={columns}
      actionRef={actionRef}
      cardBordered
      request={async (params = {}, sort, filter) => {
        console.log(params,sort, filter);
        // 此处的params就是用户在查询表单中指定的字段
        let res = await cakeGet({...params},sort.price)
        return {
          data:res.data.results,
          success:true
        }
      }}
      editable={{
        type: "multiple",
      }}
      columnsState={{
        persistenceKey: "pro-table-singe-demos",
        persistenceType: "localStorage",
        onChange(value) {
          console.log("value: ", value);
        },
      }}
      rowKey="id"
      search={{
        labelWidth: "auto",
      }}
      options={{
        setting: {
          listsHeight: 400,
        },
      }}
      pagination={{
        pageSize: 10,
        onChange: (page) => console.log(page),
      }}
      dateFormatter="string"
      headerTitle="高级表格"
      toolBarRender={() => [
        <Button key="button" icon={<PlusOutlined />} type="primary">
          新建
        </Button>,
        <Dropdown key="menu" overlay={menu}>
          <Button>
            <EllipsisOutlined />
          </Button>
        </Dropdown>,
      ]}
    />
  );
}
